package lessenIP;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

public class TestInetAddress {
    public static void main(String[] args) {
        InetAddress inetAddress1= null;
        try {
            // 查询本机地址
            inetAddress1 = InetAddress.getByName("127.0.0.1");
            System.out.println(inetAddress1);
            InetAddress inetAddress2= InetAddress.getByName("localhost");
            System.out.println(inetAddress2);
            InetAddress inetAddress3= InetAddress.getLocalHost();
            System.out.println(inetAddress3);
            // 查询网站IP地址
            InetAddress inetAddress4= InetAddress.getByName("www.baidu.com");
            System.out.println(inetAddress4);
            //
            InetSocketAddress socketAddress = new InetSocketAddress(inetAddress1, 8080);
            System.out.println(socketAddress);
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }

    }
}

